package cn.tansanqinger.controller.group;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.tansanqinger.service.group.IGroupAndNumberService;
import cn.tansanqinger.util.PageData;

@Controller
@RequestMapping("/admin/group")
public class ReportGroupController {

	@Autowired
	private IGroupAndNumberService service;
	
	@RequestMapping("/list2")
	public ModelAndView list2(ModelAndView mv) {
		mv.setViewName("group/list2");
		return mv;
	}
	
	/**
	 * 查询被举报的群聊信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/selectReportGroup")
	public @ResponseBody String selectCondition(HttpServletRequest request) {
		try {
			return new ObjectMapper().writeValueAsString(service.selectGroup(request, 1));
		} catch (Exception e) {}
		return null;
	}
	
	
	/**
	 * 查看群里面聊天信息
	 * @param request
	 * @param mv
	 * @return
	 */
	@RequestMapping("/selectChatMessage")
	public ModelAndView selectChatMessage(HttpServletRequest request, ModelAndView mv) {
		Map<String, Object> map = service.selectChatMessage(request);
		mv.addObject("reportusers", map.get("reportusers"));
		mv.addObject("chatmessage", map.get("chatmessage"));
		mv.setViewName("group/selectChatMessage");
		return mv;
	}
	
	/**
	 * 封禁群聊
	 * @param request
	 * @return
	 */
	@RequestMapping("/reportGroup")
	@ResponseBody
	public Map<String, Object> reportGroup(HttpServletRequest request) {
		return service.bannedGroup(request);
	}
	
	/**
	 * 忽略相关举报
	 * @param request
	 * @return
	 */
	@RequestMapping("/ignoreGroup")
	@ResponseBody
	public Map<String, Object> ignoreGroup(HttpServletRequest request){
		return service.ignoreGroup(request);
	}
	
	/**
	 * 封禁用户
	 * @param request
	 * @return
	 */
	@RequestMapping("/reportGroupUser")
	@ResponseBody
	public Map<String, Object> reportGroupUser(HttpServletRequest request) {
		return service.bannedGroupNumber(request);
	}
}
